/*
 * File:   Rastrigin.h
 * Author: jcrada
 *
 * Created on 26 May 2011, 1:00 PM
 */

#ifndef ECB_RASTRIGIN_H
#define	ECB_RASTRIGIN_H

#include "ecb/base/Problem.h"

namespace ecb {

        /* Source:
     * @incollection{springer-dif.evo,
            Author = {Price, Kenneth and Storn, Rainer M. and Lampinen, Jouni A.},
            title={{Appendix}},
            booktitle = {Differential Evolution: A Practical Approach to Global Optimization},
            series={Natural Computing Series},
            editor={Rozenberg, G. and Bäck, Th. and Eiben, A. E. and Kok, J. N. and Spaink, H. P.},
            publisher = {Springer-Verlag Berlin Heidelberg},
            pages = {513-533},
            year = {2005}
            }
     *
     * Range: -5.12 - 5.12
     */
    class Rastrigin : public Problem {
    public:

        Rastrigin(const std::string& id = "Rastrigin", const std::string& name = "Rastrigin",
                int dimensions = 0, scalar minimum = -5.12, scalar maximum = 5.12,
                bool minimization = true) :
        Problem(id, name, dimensions, minimum, maximum, minimization) { }

        scalar f(const std::vector<scalar>& x) {
            scalar result = 0.0;
            for (size_t i = 0; i < x.size(); ++i) {
                result += x[i] * x[i] - 10 * std::cos(2 * M_PI * x[i]) + 10;
            }
            return result;
        }

    };
}


#endif	/* ECB_RASTRIGIN_H */

